package service.article;

import java.rmi.RemoteException;
import java.util.ArrayList;

import dbExceptions.BadComboException;
import dbExceptions.DataBaseErrorException;
import dbExceptions.MissingComboException;
import business.BusinessFacade;
import business.article.interfaces.ArticleMgt;
import article.entities.ArticleVO;
import article.entities.CategoryVO;
import article.entities.ComboVO;
import article.entities.IngredientVO;
import article.exceptions.BadArticleException;
import article.exceptions.BadCategoryException;
import article.exceptions.IncompleteArticleException;
import article.exceptions.MissingArticleException;
import article.exceptions.MissingCategoryException;
import article.exceptions.NotHereException;
import article.interfaces.ArticleRemoteMgt;

public class ArticleRemoteMgr implements ArticleRemoteMgt {

	/**
	 * Implementacion del Singleton
	 */
	private static ArticleRemoteMgr instance = null;

	private ArticleRemoteMgr() {
	}

	public static ArticleRemoteMgr getInstance() throws RemoteException {
		if (instance == null)
			instance = new ArticleRemoteMgr();
		return instance;
	}

	/**
	 * Termina la implementacion de Singleton
	 */

	// ARTICLE
	public void addArticle(ArticleVO artNew) throws RemoteException,
			IncompleteArticleException, MissingCategoryException,
			DataBaseErrorException, BadCategoryException,
			MissingArticleException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		artMgt.addArticle(artNew);
	}

	public void updateArticle(ArticleVO artUpt) throws RemoteException,
			NotHereException, IncompleteArticleException,
			MissingCategoryException, DataBaseErrorException,
			BadCategoryException, MissingArticleException, BadArticleException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		artMgt.updateArticle(artUpt);
	}

	public void deleteArticle(ArticleVO artDel) throws RemoteException,
			NotHereException, MissingArticleException, BadArticleException,
			DataBaseErrorException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		artMgt.deleteArticle(artDel);
	}

	public ArticleVO[] getArticles() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getArticles();
	}	

	@Override
	public ArrayList<ArticleVO> getAllArticles() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getAllArticles();
	}

	// INGREDIENT
	public IngredientVO[] getAllIngredients() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getAllIngredients();
	}

	
	public IngredientVO[] getInStockIngredients() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getInStockIngredients();
	}

	
	public IngredientVO[] getOutStockIngredients() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getOutStockIngredients();
	}
	
	public void addOutOfStock(ArrayList<IngredientVO> ingredientes)
			throws RemoteException {
		BusinessFacade.getInstance().getArticleMgt().addOutOfStock(ingredientes);		
	}

	public void addInStock(ArrayList<IngredientVO> ingredientes)
			throws RemoteException {
		BusinessFacade.getInstance().getArticleMgt().addInStock(ingredientes);		
	}

	
	public void newIngredient(String name) throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		artMgt.newIngredient(name);
	}

	// CATEGORY
	public CategoryVO[] getCategories() throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		return artMgt.getCategories();
	}

	
	public void newCategory(String name) throws RemoteException {
		ArticleMgt artMgt = BusinessFacade.getInstance().getArticleMgt();
		artMgt.newCategory(name);
	}

	//COMBO
	public void newCombo(ComboVO comb) throws MissingCategoryException,
			MissingComboException, BadCategoryException, RemoteException {
		BusinessFacade.getInstance().getArticleMgt().newCombo(comb);		
	}

	public void deleteCombo(ComboVO comb) throws MissingArticleException,
			BadArticleException, DataBaseErrorException, RemoteException {
		BusinessFacade.getInstance().getArticleMgt().deleteCombo(comb);		
	}

	public void updateCombo(ComboVO comb) throws MissingComboException,
			BadComboException, BadCategoryException, MissingCategoryException,
			DataBaseErrorException, RemoteException {
		BusinessFacade.getInstance().getArticleMgt().updateCombo(comb);		
	}

	@Override
	public ComboVO[] getCombos() throws RemoteException {
		return BusinessFacade.getInstance().getArticleMgt().getComos();
	}

}
